package web.servlet;

import domain.Account;
import domain.Order;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import service.OrderService;

import java.io.IOException;
import java.util.List;

public class myOrderServlet extends HttpServlet {
    private static final String MY_ORDERS = "/WEB-INF/jsp/order/myOrder.jsp";

    private List<Order> orderList;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();

        OrderService orderService = new OrderService();
        Account account = (Account) session.getAttribute("loginAccount");
        orderList = orderService.getOrderByUsername(account.getUsername());
        session.setAttribute("orderList", orderList);
        req.getRequestDispatcher(MY_ORDERS).forward(req,resp);
    }
}
